﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullte : MonoBehaviour
{
    Rigidbody2D rigidbody2d;
    bool ishit;
    private SpriteRenderer sprite;
    void Start()
    {
        rigidbody2d = GetComponent<Rigidbody2D>();
        sprite=GetComponent<SpriteRenderer>();
        rigidbody2d.AddForce(Vector3.right*0.05f);
    }

    void Update()
    {
        if (ishit) return;
        transform.Rotate(new Vector3(0,0,-15f));
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (ishit) return;
        if (collision.tag == "僵尸")
        {
            ishit = true;
            sprite.sprite = GameManager.instance.Gameconf.sprite;
            rigidbody2d.velocity = Vector2.zero;
            rigidbody2d.gravityScale = 1;
            Invoke("Destroy", 0.5f);
        }
    }
    private void Destroy()
    {
        Destroy(gameObject);
    }
}
